package net.lab1024.sa.admin.module.business.place.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.admin.module.business.category.domain.form.CategoryTreeQueryForm;
import net.lab1024.sa.admin.module.business.category.domain.vo.CategoryTreeVO;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceAddForm;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceQueryForm;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceTreeQueryForm;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceUpdateForm;
import net.lab1024.sa.admin.module.business.place.domain.vo.PlaceTreeVO;
import net.lab1024.sa.admin.module.business.place.domain.vo.PlaceVO;
import net.lab1024.sa.admin.module.business.place.service.PlaceService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 地址 Controller
 *
 * @Author syf
 * @Date 2025-05-21 16:29:55
 * @Copyright 畅想科技
 */

@RestController
@Tag(name = "")
public class PlaceController {

    @Resource
    private PlaceService placeService;

    @Operation(summary = "分页查询 @author syf")
    @PostMapping("/place/queryPage")
    public ResponseDTO<PageResult<PlaceVO>> queryPage(@RequestBody @Valid PlaceQueryForm queryForm) {
        return ResponseDTO.ok(placeService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author syf")
    @PostMapping("/place/add")
    public ResponseDTO<String> add(@RequestBody @Valid PlaceAddForm addForm) {
        return placeService.add(addForm);
    }

    @Operation(summary = "更新 @author syf")
    @PostMapping("/place/update")
    public ResponseDTO<String> update(@RequestBody @Valid PlaceUpdateForm updateForm) {
        return placeService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author syf")
    @PostMapping("/place/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return placeService.batchDelete(idList);
    }
    @Operation(summary = "查询类目层级树 @author 胡克")
    @PostMapping("/place/tree")
//    @SaCheckPermission("place:tree")
    public ResponseDTO<List<PlaceTreeVO>> queryTree(@RequestBody @Valid PlaceQueryForm queryForm) {
        return placeService.queryTree(queryForm);
    }
    @Operation(summary = "单个删除 @author syf")
    @GetMapping("/place/delete/{placeId}")
    public ResponseDTO<String> batchDelete(@PathVariable Long placeId) {
        return placeService.delete(placeId);
    }
}
